<% layout("../../includes/layout-form-v2") -%>
<form id="form" class="form-submission backend <%-action%> id_<%- id %>" title="<%-controller%>" action='/backend/<%-controller%>/<%- action %>/<%- id %>' method='post' onsumbit="return myFunction()" >
   
        <div class="box-body">
        
                   
             <div class="input-group">
            	<p class="error_msg  error_in_branch_id"></p>
                <span class="input-group-addon"><b>User Group</b></span>
                <select name="user_group_id" class="form-control">
		         <% if(refData.userGroupList.length){ 
			      	 	 for(var i = 0; i < refData.userGroupList.length;i++) {%>
			                  	<option <%= (record['user_group_id'] ==  refData.userGroupList[i].id) ? "selected" : "" %> value="<%- refData.userGroupList[i].id %>" ><%- refData.userGroupList[i].name %></option>
			      <%     }
			        }
			      %>   
                </select>
           </div><br/>

           <div class="input-group">
            	<p class="error_msg  error_in_branch_id"></p>
                <span class="input-group-addon"><b>Branch (<%-record['branch_id']%>)</b></span>
                <select name="branch_id" id="branch_list" class="form-control">
		         <% if(refData.branchList.length){ 
			      	 	 for(var i = 0; i < refData.branchList.length;i++) {%>
			                  	<option <%= (record['company_id'] ==  refData.branchList[i].id) ? "selected" : "" %> id="<%- refData.branchList[i].company_id %>" value="<%- refData.branchList[i].id %>" ><%- refData.branchList[i].name %></option>
			      <%     }
			        }
			      %>   
                </select>
                <% if(record['branch_id'] == null || record['branch_id'] == ""){ %>
                	<input type="hidden" name="company_id" value="<%-refData.branchList[0].id %>" id="company_id" />
                <%}else{ %>
			      	<input type="hidden" name="company_id" id="company_id"   value="<%- record['branch_id'] %>"/>
			    <% } %>
                
           </div><br/>

            <div class="input-group">
			    <span class="input-group-addon"><b>Username</b></span>
			    <input name="username" type="text" class="form-control" id="username" value="<%- record['username'] %>" placeholder="Enter username">
			    <span class="input-group-addon error_msg_field err_username"><b class="error_msg error_in_username"></b></span>
			</div><br/>
            
            <div class="input-group">
			    <span class="input-group-addon"><b>Password</b></span>
			    <input name="password" type="password" class="form-control" id="password" value="<%- record['password'] %>" placeholder="Enter password">
			    <span class="input-group-addon error_msg_field err_password"><b class="error_msg error_in_password"></b></span>
			</div><br/>
            
            <div class="input-group">
            	<p class="error_msg  error_in_confirm_password"></p>
                <span class="input-group-addon"><b>Confirm Password</b></span>
                <input name="confirm_password" type="password" class="form-control" placeholder="Enter confirm password">
            </div><br/>
            
            <div class="input-group">
			    <span class="input-group-addon"><b>Email</b></span>
			    <input name="email" type="text" class="form-control" id="email" value="<%- record['email'] %>" placeholder="Enter email">
			    <span class="input-group-addon error_msg_field err_password"><b class="error_msg error_in_email"></b></span>
			</div><br/>
            
           <div class="input-group">
			    <span class="input-group-addon"><b>First Name</b></span>
			    <input name="firstname" type="text" class="form-control" id="firstname" value="<%- record['firstname'] %>" placeholder="Enter first name">
			    <span class="input-group-addon error_msg_field err_firstname"><b class="error_msg error_in_firstname"></b></span>
			</div><br/>
            
            <div class="input-group">
			    <span class="input-group-addon"><b>Middle Name</b></span>
			    <input name="middlename" type="text" class="form-control" id="middlename" value="<%- record['middlename'] %>" placeholder="Enter middle name">
			    <span class="input-group-addon error_msg_field err_middlename"><b class="error_msg error_in_middlename"></b></span>
			</div><br/>
            
            <div class="input-group">
			    <span class="input-group-addon"><b>Last Name</b></span>
			    <input name="lastname" type="text" class="form-control" id="lastname" value="<%- record['lastname'] %>" placeholder="Enter last name">
			    <span class="input-group-addon error_msg_field err_lastname"><b class="error_msg error_in_lastname"></b></span>
			</div><br/>
            
            <div class="input-group">
            	<p class="error_msg error_in_status"> <%- record['error_in_status'] %> </p>
                <span class="input-group-addon"><b>Status</b></span>
                <select name="status" class="form-control">
               	   	<option value="0" <%- (record['status'] == "0")?"selected":"" %>>Enable</option>
        			<option value="1" <%- (record['status'] == "1")?"selected":"" %>>Disable</option>
                </select>
            </div>
          
        </div><!-- /.box-body -->

    <div class="box-footer">
        <input type="submit" class="btn btn-primary btn-lg <%-action%>" title="<%-controller %>" value="Save" />
    </div>
</form>


<script type="text/javascript">
 $(document).ready(function(){

 });

 $("#branch_list").change(function() {
	  var companyId = $(this).children(":selected").attr("id");

	  $("#company_id").val(companyId);
 });
</script>